import {
  getArticleInfo
} from '../../api/index'
import {
  articleType,
  showType,
  findTypeByValue,
} from '../../utils/type';
const app = getApp()
Page({
  data: {
    logined: true,
    baseCls: 'page_account',
    indicator_dots: true,
    indicator_color: "#ffffff",
    indicator_active_color: "#F8626E",
    autoplay: true,
    interval: 3000,
    circular: true,
    checked: false,
    articleType,
    showType
  },
  onLoad(options) {
    this.setData({
      id: options.id
    })
  },
  onShow: function () {
    let userInfo = wx.getStorageSync('userInfo');
    if (userInfo) {
      this.setData({
        logined: true,
        show: false,
        userInfo: userInfo
      })
      this.article_info();
    } else {
      this.setData({
        logined: false,
        show: true
      })
    }
  },

  // 图片加载完成回调
  imageLoadSuccess(e) {
    const imgDetail = e.detail
    this.setData({
      imgStyle: `width: ${imgDetail.width * this.data.pixelRatio}rpx; height: ${imgDetail.height * this.data.pixelRatio}rpx;`
    })
  },

  // 资讯详情
  article_info() {
    var that = this;
    var id = that.data.id;
    getArticleInfo(id).then(res => {
      const articleInfo = res.data
      articleInfo.type = findTypeByValue(articleInfo.type, articleType).label
      articleInfo.status = findTypeByValue(articleInfo.status, showType).label
      articleInfo.content = articleInfo.content.replaceAll('\n', '<br/>')
      console.log(articleInfo.content);
      if (articleInfo.status == '公开') {
        var checked = true
      } else {
        var checked = false
      }
      that.setData({
        articleInfo: articleInfo,
        checked: checked
      })
    })

  },

})